<?php
include('include/config.inc.php');
if(!isset($_SESSION['s_activId'.$cfgPack])
  || (isset($_SESSION['s_userType'.$cfgPack]) && isset($cfgFileNames['typeofcall'][$_SESSION['s_userType'.$cfgPack]]) 
      && $cfgFileNames['typeofcall'][$_SESSION['s_userType'.$cfgPack]] == 0))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{	
  $typeOfCallIdDetailArray = array();
  $type                    = "";
  $i                       = 0;  
  $typeOfCallId            = isset($_REQUEST['typeOfCallId']) ? $_REQUEST['typeOfCallId'] : 0;

  // after post : start 
  if(isset($_POST['type']))
  {
    if($typeOfCallId > 0)
    {
      $updateTechnician = "UPDATE typeofcall SET type  = '".$_POST['type']."'
                                           WHERE typeOfCallId  = '".$_REQUEST['typeOfCallId']."'";
      $updateTechnicianRes  = mysql_Query($updateTechnician);
      if(!$updateTechnicianRes)
        die("Insert Query Not Inserted : ".mysql_error());
      else
        header("Location:typeOfCall.php");
    }
    else
    {
      $insertTechnician = "INSERT INTO typeofcall (type)
                            VALUE('".$_POST['type']."')";
      $insertTechnicianResult = mysql_query($insertTechnician);
      if(!$insertTechnicianResult)
        die("Insert Query Not Inserted : ".mysql_error());
      else
        header("Location:typeOfCall.php");
    }
  }    
  // after post : end
  
  $selectTechnician = "SELECT typeOfCallId,type
                         FROM typeofcall
                     ORDER BY type";
  $selectTechnicianResult = mysql_query($selectTechnician);
  $ItemInRow = mysql_num_rows($selectTechnicianResult);
  while($ItemInRow = mysql_fetch_array($selectTechnicianResult))
  {
    $typeOfCallIdDetailArray[$i]['typeOfCallId']  = $ItemInRow['typeOfCallId'];
    $typeOfCallIdDetailArray[$i]['type']          = $ItemInRow['type'];
    
    if($ItemInRow['typeOfCallId'] == $typeOfCallId)
    {
      $type  = $ItemInRow['type'];  
    }
    $i++;     
  }    
  include("./bottom.php");
  $smarty->assign("typeOfCallId",$typeOfCallId);
  $smarty->assign("type",$type);
  $smarty->assign("typeOfCallIdDetailArray",$typeOfCallIdDetailArray);
  $smarty->assign("i",$i);
  $smarty->display("typeOfCall.tpl");
}
?>